package com.sofoscorp.android.gestcobranzamobile;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class KNVK_BO {
	private String gv_tabName = "KNVK";
	private ConexionDB go_conexDB;
	private Cursor gc_KNVK;
	private SQLiteDatabase go_db;
	
	private KNVK_Str gs_KNVK = null;
	String[] gt_campos = new String[]{"KUNNR", "ABTNR", "NAME1", "NAMEV"};
	
	public KNVK_BO(){
		go_conexDB = new ConexionDB();
	}
	
	public KNVK_Str get_SingleByKey(String ivKUNNR){
		String lv_Where = "KUNNR = ?";
		String[] lt_WhereArgs;
		
		if(ivKUNNR.equals("") || ivKUNNR.equals(null)){
			gs_KNVK = null;
		}else {
			gc_KNVK = null;
			lt_WhereArgs = new String[]{ivKUNNR};
			
			//Pasar el Path de DB
			go_conexDB.serialization(go_conexDB.C_PATH_FROMSAP);

			//Verificar si existe conexion con la DB
			if (go_conexDB.checkConexDB()) {

				//Obtener la DB
				go_db = go_conexDB.getGo_DB();
				
				try {
					//Ejecutar Select a la DB
					gc_KNVK = go_db.query(gv_tabName, gt_campos, lv_Where, lt_WhereArgs, null, null, null, null);
					if (gc_KNVK.moveToFirst()) {
						gs_KNVK = new KNVK_Str(	gc_KNVK.getString(0), 
												gc_KNVK.getString(1), 
												gc_KNVK.getString(2), 
												gc_KNVK.getString(3));
					}else{
						gs_KNVK = null;
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
			}else{
				gs_KNVK = null;
			}
		}

		go_db.close();
		gc_KNVK.close();
		return gs_KNVK;
	}
}
